package com.shundr.shipper.truck.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shundr.shipper.R;
import com.shundr.shipper.frame.util.StringUtil;
import com.shundr.shipper.truck.model.UserTrackInfo;

/**
 * 
 * UserTruckTimeAdapter
 * 
 * @author larry 2015-6-27 下午2:54:40 
 * @version 1.0.0
 *
 */
public class UserTruckTimeAdapter extends BaseAdapter {
	private List<UserTrackInfo> mList;
	private Context mContext;
	
	public UserTruckTimeAdapter(Context context, List<UserTrackInfo> list) {
		this.mContext = context;
		this.mList = list;
	}

	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHold viewHold = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_user_truck_time,null);
			viewHold = new ViewHold();
			viewHold.tvAddress = (TextView) convertView.findViewById(R.id.tv_address);
			viewHold.tvTime = (TextView) convertView.findViewById(R.id.tv_time);
			convertView.setTag(viewHold);
		}else{
			viewHold = (ViewHold) convertView.getTag();
		}
		try {
			UserTrackInfo info = mList.get(position);
			if (!StringUtil.isNull(info.getCity())) {
				viewHold.tvAddress.setText(info.getCity());
			}else{
				viewHold.tvAddress.setText("地点未知");
			}
			
			if (!StringUtil.isNull(info.getUpdateTime())) {
				viewHold.tvTime.setText(info.getUpdateTime());
			}else{
				viewHold.tvTime.setText("时间未知");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return convertView;
	}

	class ViewHold {
		TextView tvAddress;
		TextView tvTime;
	}
}
